* ======================================
* -------- Immigrants Alternate --------
* ======================================


	use $dta\EstimationSample.dta, clear

	
* Estimate models
* ===============

	egen idbsu = group(Voter_id Voter_bsu)
	gen period = 1*(year == 2019)
	xtset idbsu period
	estimates clear

	keep if Imm1Any == 1 // set sample
	
	* Birthcountry only (Imm3a)
	sum Voter_turnout 		// Mean depvar
	local meandepvar = string(r(mean)*100, "%15.2fc")
	gen Same_bc = Imm3aSame	
	eststo m_bc: xtreg Voter_turnout Same_bc i.period, ///
		i(idbsu) fe cluster(Voter_bsu)
	quietly estadd local meandep `meandepvar', replace


	* Occupation only (Imm3b)
	sum Voter_turnout 	// Mean depvar
	local meandepvar = string(r(mean)*100, "%15.2fc")	
	gen Same_occ = Imm3bSame
	eststo m_occ: xtreg Voter_turnout Same_occ i.period, ///
		i(idbsu) fe cluster(Voter_bsu)
	quietly estadd local meandep `meandepvar', replace

	
	* Both alone
	sum Voter_turnout	// Mean depvar
	local meandepvar = string(r(mean)*100, "%15.2fc")
	gen Same_b = Imm1Same
	eststo m_both: xtreg Voter_turnout Same_b i.period, ///
		i(idbsu) fe cluster(Voter_bsu)
	quietly estadd local meandep `meandepvar', replace

	
	* All three combined
	sum Voter_turnout	// Mean depvar
	local meandepvar = string(r(mean)*100, "%15.2fc")
	eststo m_all: xtreg Voter_turnout Same* i.period, ///
		i(idbsu) fe cluster(Voter_bsu)
	quietly estadd local meandep `meandepvar', replace



* Export table
* ============

	esttab m_* ///
		using $tbls\ImmigrantsAlternate.tex, replace  style(tex) ///
		prehead("\begin{tabular}{l*{5}{c}} \hline\hline \\  ") ///
		posthead("\hline \\") ///
		fragment ///
		nomtitles ///
		label se b(%9.3f) se(%9.3f) nostar ///	
		order(Same_bc Same_occ Same_b) ///
		refcat(Same_bc "\shortstack{Any District}") ///
		coeflabels(Same_bc "Same District (Birthcountry)" ///
			Same_occ "Same District (Occupation)" ///
			Same_b "Same District (Both)") ///
		drop(_cons *.period ) noomitted nobaselevels ///
		nonotes stats(N N_clust meandep, labels( ///
			"Observations" "Clusters" "Mean turnout (\%)") ///
			fmt(%15.0fc %15.0fc %15.0fc %15.0fc %15.0fc)) ///
		substitute(\_ _) ///
		prefoot("\hline") ///
		postfoot("\hline\hline \\ \end{tabular}")
